package com.fjwt.gz.mgr.ctrl.ifcode;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fjwt.gz.core.model.ApiRes;
import com.fjwt.gz.db.dto.PayAuthDTO;
import com.fjwt.gz.db.vo.PayAuthVO;
import com.fjwt.gz.mgr.ctrl.CommonCtrl;
import com.fjwt.gz.service.impl.PayAuthService;
import com.fjwt.gz.service.impl.SysConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 通道配置
 * @Author: Will
 * @Date: 2024-01-25
 * @Version: 1.0
 */
@RestController
@Slf4j
@RequestMapping("/api/ifCode")
public class IfCodeController extends CommonCtrl{

    @Autowired
    private PayAuthService payAuthService;
    @Autowired
    private SysConfigService sysConfigService;

    /**
     * 查询三方出资列表
     * @return
     */
    @PreAuthorize("hasAnyAuthority('ENT_IFCODE_INFO')")
    @GetMapping
    public ApiRes list() {
        PayAuthDTO payAuthDTO = getObject(PayAuthDTO.class);
        log.info("pc端查询三方出资列表，请求地址：/api/ifCode，请求参数：{}", JSONUtil.toJsonStr(payAuthDTO));
        IPage<PayAuthVO> page = payAuthService.selectPageList(getIPage(true), payAuthDTO);
        log.info("pc端查询三方出资列表，请求地址：/api/ifCode，响应结果：{}",  JSONUtil.toJsonStr(page));
        return ApiRes.page(page);
    }

    /**
     * 新增出资方
     * @return
     */
    @PreAuthorize("hasAnyAuthority('ENT_IFCODE_INFO_ADD')")
    @RequestMapping(value = "", method = RequestMethod.POST)
    public ApiRes add() {
        PayAuthDTO payAuthDTO = getObject(PayAuthDTO.class);
        log.info("pc端新增三方出资方，请求地址：/api/ifCode，请求参数：{}", JSONUtil.toJsonStr(payAuthDTO));
        return payAuthService.insert(payAuthDTO);
    }

    /**
     * 修改出资方
     * @return
     */
    @PreAuthorize("hasAnyAuthority('ENT_IFCODE_INFO_EDIT')")
    @RequestMapping(value = "", method = RequestMethod.PUT)
    public ApiRes update() {
        PayAuthDTO payAuthDTO = getObject(PayAuthDTO.class);
        log.info("pc端修改三方出资方，请求地址：/api/ifCode，请求参数：{}", JSONUtil.toJsonStr(payAuthDTO));
        return payAuthService.revamp(payAuthDTO);
    }
}
